package com.yxp.offer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Auther : yxpweb
 * @Date : 2021/8/15 20:18
 * @Description: 剑指 Offer 05. 替换空格
 */
public class Problem05 {

    public static void main(String[] args) {
        String he = "hello world";
        Problem05 problem05 = new Problem05();
        System.out.println(problem05.replaceSpace(he));
    }

    public String replaceSpace(String s) {
        if (s == null) {
            return null;
        }
        char[] strArray = s.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0, j = 0; i < strArray.length; i++) {
            if (strArray[i] == ' ') {
                stringBuilder.append("%20");
            } else {
                stringBuilder.append(strArray[i]);
            }
        }
        return stringBuilder.toString();
    }
}
